<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>练习8</title>
</head>

<body>

</body>
<script>
    //1.查看字符串中是否包含数字
    function haveNumber(str) {
        return /\d/.test(str);
    }

    console.log(haveNumber("abc123"));
    console.log(haveNumber("abc"));

    //2.验证中文名，且2到5位
    function isChineseName(name) {
        return /^[\u4e00-\u9fa5]{2,5}$/.test(name);
    }

    console.log(isChineseName("张三"));
    console.log(isChineseName("Tom"));

    //3.将以下字符串中的数字全部筛选出来  中国移动:10086,中国联通:10010,中国电信:10000  match()
    let str = "中国移动:10086,中国联通:10010,中国电信:10000";
    let number = str.match(/\d+/g);

    console.log(number);

    //4.提取年月日的日期中的年份 2022-10-20
    let date = "2022-10-20";
    date.match(/^(\d{4})-\d{2}-\d{2}$/);
    console.log(RegExp.$1);

    //5.将邮箱的各部分进行提取  123456@qq.com
    let email = "123456@qq.com";
    let parts = email.match(/^(\w+)@([a-zA-Z0-9]+)\.([a-zA-Z]{2,})$/);

    console.log("用户名: " + parts[1]);
    console.log("域名: " + parts[2]);
    console.log("后缀: " + parts[3]);

    //6.'abc   123   aaa   bbb' 将此字符串中的空格替换成AAA  replace()
    let str1 = "abc   123   aaa   bbb";
    let newStr = str1.replace(/\s+/g, "AAA");

    console.log(newStr);

    //7.切割字符串  abc#123@bbb  split()
    let str2 = "abc#123@bbb";
    let parts1 = str2.split(/[#@]/);

    console.log(parts1);
</script>

</html>